package com.gxitsky.classload.demo1;

import org.reflections.vfs.Vfs;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author gxing
 * @desc 虚拟文件
 * @date 2021/12/28
 */
public class ContainerFile implements Vfs.File {
    private String name;
    private String path;
    // 这里不能传 InputStream过来，扫描class时，多次读取流的读取下标不会重置（查这个bug查了一整天）
    private byte[] bytes;


    public ContainerFile(String name, String path, byte[] bytes) {
        this.name = name;
        this.path = path;
        this.bytes = bytes;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getRelativePath() {
        return path;
    }

    @Override
    public InputStream openInputStream() throws IOException {
        return new ByteArrayInputStream(bytes);
    }
}
